<template>
  <div class="account-settings-info-view">
    <a-row :gutter="16">
      <a-col :md="24" :lg="16">

        <a-form layout="vertical">
          <a-form-item
            label="昵称"
          >
            <a-input placeholder="给自己起个名字" v-model="adminData.username" />
          </a-form-item>
          <a-form-item
            label="商户号"
          >
            <a-input placeholder="商户号" v-model="adminData.merchantId" />
          </a-form-item>
          <a-form-item
            label="身份"
          >
            <a-input placeholder="身份" v-model="adminData.realname" />
          </a-form-item>

          <a-form-item
            label="电话号码"
            :required="false"
          >
            <a-input placeholder="123232323" v-model="adminData.phone"/>
          </a-form-item>
          <a-form-item
            label="加密方式"
            :required="false"
          >
            <a-select defaultValue="aes-256-cfb" >
              <a-select-option :value='1'>aes-256-cfb</a-select-option>
              <a-select-option :value='2'>aes-128-cfb</a-select-option>
              <a-select-option :value='3'>chacha20</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item
            label="连接密码"
            :required="false"
          >
            <a-input placeholder="h3gSbecd" v-model="adminData.password"/>
          </a-form-item>

          <a-form-item>
            <a-button type="primary" @click="update">提交</a-button>
            <a-button style="margin-left: 8px">保存</a-button>
          </a-form-item>
        </a-form>

      </a-col>
      <a-col :md="24" :lg="8" :style="{ minHeight: '180px' }">
        <div class="ant-upload-preview" @click="$refs.modal.edit(1)" >
          <a-icon type="cloud-upload-o" class="upload-icon"/>
          <div class="mask">
            <a-icon type="plus" />
          </div>
          <img :src="option.img"/>
        </div>
      </a-col>

    </a-row>


  </div>
</template>

<script>
import { getBasicList,amendList } from '@/api/mall/account.js'
import querystring from 'querystring'

export default {
  data () {
    return {
      // cropper
      // 参数
      parameter:{
        adminId:null,
        adminDTO:null
      },
      adminData:{
        id: null,
        merchantId: null,
        password:null,
        phone:null,
        username:null,
      },
      // 修改参数
      // 基本信息数据
      preview: {},
      option: {
        img: '/avatar2.jpg',
        info: true,
        size: 1,
        outputType: 'jpeg',
        canScale: false,
        autoCrop: true,
        // 只有自动截图开启 宽度高度才生效
        autoCropWidth: 180,
        autoCropHeight: 180,
        fixedBox: true,
        // 开启宽度和高度比例
        fixed: true,
        fixedNumber: [1, 1]
      }
    }
  },
  created () {
    //进入页面获取商户信息
    this.getList()
  },
  methods: {
    setavatar (url) {
      this.option.img = url
    }, 
    getList(){ // 获取数据
    this.parameter.adminDTO = null
      getBasicList(Object.assign(this.parameter))
        .then(res => {
          console.log(res)
          this.adminData = res.data
        })
    },
    update(){//修改数据
    var that=this;
    this.parameter.adminId = this.adminData.id
    let adminParameter={
        id: that.adminData.id,
        merchantId: that.adminData.merchantId,
        password:that.adminData.password,
        phone:that.adminData.phone,
        username:that.adminData.username,
      };
    this.parameter.adminDTO = adminParameter
      amendList(Object.assign(this.parameter))
        .then(res => {
          console.log(res)    
          this.getList()  
        })
    }
  }
}
</script>

<style lang="less" scoped>

  .avatar-upload-wrapper {
    height: 200px;
    width: 100%;
  }

  .ant-upload-preview {
    position: relative;
    margin: 0 auto;
    width: 100%;
    max-width: 180px;
    border-radius: 50%;
    box-shadow: 0 0 4px #ccc;

    .upload-icon {
      position: absolute;
      top: 0;
      right: 10px;
      font-size: 1.4rem;
      padding: 0.5rem;
      background: rgba(222, 221, 221, 0.7);
      border-radius: 50%;
      border: 1px solid rgba(0, 0, 0, 0.2);
    }
    .mask {
      opacity: 0;
      position: absolute;
      background: rgba(0,0,0,0.4);
      cursor: pointer;
      transition: opacity 0.4s;

      &:hover {
        opacity: 1;
      }

      i {
        font-size: 2rem;
        position: absolute;
        top: 50%;
        left: 50%;
        margin-left: -1rem;
        margin-top: -1rem;
        color: #d6d6d6;
      }
    }

    img, .mask {
      width: 100%;
      max-width: 180px;
      height: 100%;
      border-radius: 50%;
      overflow: hidden;
    }
  }
</style>
